import 'reflect-metadata'
const requireDeractor:ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => {
    let reqireParams:number[] = [];
    reqireParams.push(parameterIndex);
    Reflect.defineMetadata('required',reqireParams,target,propertyKey);
}

const methodDeractor:MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor:PropertyDescriptor) => {
    const method = descriptor.value;
    descriptor.value = function() {
        const requireParams:number[] = Reflect.getMetadata('required',target,propertyKey) || [];
        requireParams.forEach(index => {
            if(index > arguments.length || arguments[index] == undefined){
                throw new Error("请传递必要的参数")
            }
        })
        return method.apply(this,arguments)
    }
}

class User{
    @methodDeractor
    find(name:string,@requireDeractor id:number){
        console.log(id);
    }
}

new User().find('abc',2777);